<?xml version='1.0' encoding='UTF-8' ?>
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml"
      xmlns:h="http://java.sun.com/jsf/html"
      xmlns:ui="http://java.sun.com/jsf/facelets"
      xmlns:f="http://java.sun.com/jsf/core"
      xmlns:c="http://java.sun.com/jsp/jstl/core">
    <h:head>
        <title>SGP - Cadastro Usuário</title>
    </h:head>
    <h:body>
        <ui:insert name="header" >
            <ui:include src="cabecalho.xhtml" />
        </ui:insert>
        <div id="conteudo">
            <div id="conteudo-table-interno">
                <hr /><br />
                <h2>Inserir / Alterar</h2><br />
                <hr /><br />
                <h:form>
                    <table border="0" cellpadding="0" cellspacing="2" align="center" width="98%">            
                        <tr style="display: none;">
                            <td align="right"><label><span class="obr">*</span> ID</label></td>
                            <td width="313">
                                <div class="branco">
                                    <h:outputText id="id" value="#{beanCadastroUsuario.usuario.id}" />
                                </div>
                            </td>
                        </tr>
                        <tr>
                            <td align="right"><label><span class="obr">*</span> Nome do Usuário</label></td>
                            <td width="313">
                                <div class="branco">
                                    <h:inputText value="#{beanCadastroUsuario.usuario.nome}"/><br />
                                </div>
                            </td>
                            <td align="right"><label><span class="obr">*</span> Login</label></td>
                            <td width="313">
                                <div class="branco">
                                    <h:inputText value="#{beanCadastroUsuario.usuario.login}"/><br />
                                </div>
                            </td>
                        </tr>
                        <tr>
                            <td align="right"><label><span class="obr">*</span> Senha</label></td>
                            <td width="313">
                                <div class="branco">
                                    <h:inputSecret value="#{beanCadastroUsuario.usuario.senha}"/><br />
                                </div>
                            </td>
                            <td align="right"><label><span class="obr">*</span> Permissão</label></td>
                            <td width="313">
                                <div class="branco">
                                    <h:selectOneListbox value="#{beanCadastroUsuario.permissaoSelecionada}" size="1" converter="simpleEntityConverter" style="width: 310px;">
                                        <f:selectItem itemLabel="Selecione" itemValue=""/>
                                        <f:selectItems value="#{beanCadastroUsuario.listarPermissao}" var="per" itemLabel="#{per.permissao}" itemValue="#{per}" />
                                    </h:selectOneListbox>
                                </div>
                            </td>
                        </tr>
                        <tr>
                            <td colspan="2" align="left">
                                <span class="obr">* Campos Obrigatórios</span>
                            </td>
                            <td colspan="2" align="right">
                                <h:commandButton value="Cadastrar" class="botao" action="#{beanCadastroUsuario.cadastrarUsuario()}" rendered="#{empty beanCadastroUsuario.id}"/>
                                <h:commandButton value="Alterar" class="botao" action="#{beanCadastroUsuario.alterarUsuario()}" rendered="#{not empty beanCadastroUsuario.id}"/>
                                <h:commandButton value="Novo" class="botao" action="#{beanCadastroUsuario.novoUsuario()}" rendered="#{not empty beanCadastroUsuario.id}" />
                            </td>
                        </tr>
                    </table>
                    <div class="clear"></div>

                </h:form>
                <div class="clear"></div>
                <br />
                <hr /><br />
                <h2>Listar</h2><br />
                <hr /><br />
                <h:form>
                    <h:dataTable id="dataTableCliente" class="dataTableCliente" cellpadding="0" cellspacing="1" var="usuario" value="#{beanCadastroUsuario.listaUsuario}"  >
                        <h:column>
                            <f:facet name="header">
                                <h:outputText value="Nome do usuário"/>
                            </f:facet>
                            <h:outputText value="#{usuario.nome}" />
                        </h:column>
                        <h:column>
                            <f:facet name="header">
                                <h:outputText value="Login" />
                            </f:facet>
                            <h:outputText value="#{usuario.login}" />
                        </h:column>
                        <!--<h:column>
                            <f:facet name="header">
                                <h:outputText value="Senha" />
                            </f:facet>
                            <h:outputText value="#{usuario.senha}" />
                        </h:column>-->
                        <h:column>
                            <f:facet name="header">
                                <h:outputText value="Permissão" />
                            </f:facet>
                            <h:outputText value="#{usuario.permissao.permissao}" />
                        </h:column>
                        <h:column>
                            <f:facet name="header">
                                <h:outputText value="" />
                            </f:facet>
                            <h:commandLink action="#{beanCadastroUsuario.preparaAlteracao}"><img src="img/editar.png"/></h:commandLink>
                        </h:column>

                        <h:column>
                            <f:facet name="header">
                                <h:outputText value="" />
                            </f:facet>
                            <h:commandLink action="#{beanCadastroUsuario.excluirUsuario}"><img src="img/excluir.png" /></h:commandLink>
                        </h:column>
                    </h:dataTable>
                </h:form>
            </div> 
        </div>
    </h:body>
</html>

